package orm

import "gluenet/pkg/ops/dbi"

func UpdateAgentRuntimeHosts(c dbi.GlueDB, guid string, hosts string) error {
	if _, err := c.MetaDB().Exec(`update agent_runtime set hosts=? where guid = ?`, hosts, guid); err != nil {
		return err
	}
	return nil
}

func UpdateAgentRuntimeStatus(c dbi.GlueDB, guid string, status string) error {
	if _, err := c.MetaDB().Exec(`update agent_runtime set status=? where guid = ?`, status, guid); err != nil {
		return err
	}
	return nil
}

func UpdateAgentRuntimeContainers(c dbi.GlueDB, guid string, contaienrs string) error {
	if _, err := c.MetaDB().Exec(`update agent_runtime set containers=? where guid = ?`, contaienrs, guid); err != nil {
		return err
	}
	return nil
}

func UpdateInstancesRuntimeContainers(c dbi.GlueDB, guid string, contaienrs string) error {
	if _, err := c.MetaDB().Exec(`update instance_runtime set containers=? where guid = ?`, contaienrs, guid); err != nil {
		return err
	}
	return nil
}

func UpdateInstancesRuntimeContainersInfo(c dbi.GlueDB, guid string, contaienrs string) error {
	if _, err := c.MetaDB().Exec(`update instance_runtime set containers_info=? where guid = ?`, contaienrs, guid); err != nil {
		return err
	}
	return nil
}

func UpdateInstanceRuntimeContainersTraces(c dbi.GlueDB, guid, data string) error {
	if _, err := c.MetaDB().Exec(`insert into instance_traces (guid,traces) values (?,?) on duplicate key update traces=?`, guid, data, data); err != nil {
		return err
	}
	return nil
}

func UpdateInstancesRuntimeStatus(c dbi.GlueDB, guid string, status string) error {
	if _, err := c.MetaDB().Exec(`insert into instance_runtime (guid,status) values (?,?) on duplicate key update status=?`, guid, status, status); err != nil {
		return err
	}
	return nil
}
